-
Notifications
You must be signed in to change notification settings - Fork 177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Core] Fix Race Conditions in CMsgSubscriber #1324
[Core] Fix Race Conditions in CMsgSubscriber #1324
Conversation
- Properly implement destructor (in inherited classes)! -> Destroy may not be called in base CMsgSubscriber class as this can lead to stack unwinding (most likely causes an exception in destructor, or leads to already deleted functions of derived class being called when they are already deleted) - Correct order of RemReceiveCallback and resetting internal pointer - protect function pointer with mutex. - Make testcase "harder" to more easily trigger race conditions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
@@ -125,7 +125,8 @@ namespace eCAL | |||
return *this; | |||
} | |||
|
|||
virtual ~CMsgSubscriber() {} | |||
virtual ~CMsgSubscriber() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: use '= default' to define a trivial destructor [modernize-use-equals-default]
ecal/core/include/ecal/msg/subscriber.h:128:
- {}
+ = default;
@@ -219,9 +223,12 @@ namespace eCAL | |||
**/ | |||
bool RemReceiveCallback() | |||
{ | |||
bool ret = CSubscriber::RemReceiveCallback(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: variable 'ret' is not initialized [cppcoreguidelines-init-variables]
bool ret = CSubscriber::RemReceiveCallback(); | |
bool ret = false = CSubscriber::RemReceiveCallback(); |
@@ -245,7 +252,11 @@ namespace eCAL | |||
private: | |||
void ReceiveCallback(const char* topic_name_, const struct eCAL::SReceiveCallbackData* data_) | |||
{ | |||
MsgReceiveCallbackT fn_callback(m_cb_callback); | |||
MsgReceiveCallbackT fn_callback; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: variable 'fn_callback' is not initialized [cppcoreguidelines-init-variables]
MsgReceiveCallbackT fn_callback; | |
MsgReceiveCallbackT fn_callback = 0; |
Fixes #1318 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
@@ -245,7 +251,11 @@ namespace eCAL | |||
private: | |||
void ReceiveCallback(const char* topic_name_, const struct eCAL::SReceiveCallbackData* data_) | |||
{ | |||
MsgReceiveCallbackT fn_callback(m_cb_callback); | |||
MsgReceiveCallbackT fn_callback = nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: variable 'fn_callback' is not initialized [cppcoreguidelines-init-variables]
MsgReceiveCallbackT fn_callback = nullptr; | |
MsgReceiveCallbackT fn_callback = 0 = nullptr; |
- Properly implement destructor (in inherited classes)! -> Destroy may not be called in base CMsgSubscriber class as this can lead to stack unwinding (most likely causes an exception in destructor, or leads to already deleted functions of derived class being called when they are already deleted) - Correct order of RemReceiveCallback and resetting internal pointer - protect function pointer with mutex. - Make testcase "harder" to more easily trigger race conditions.
- Properly implement destructor (in inherited classes)! -> Destroy may not be called in base CMsgSubscriber class as this can lead to stack unwinding (most likely causes an exception in destructor, or leads to already deleted functions of derived class being called when they are already deleted) - Correct order of RemReceiveCallback and resetting internal pointer - protect function pointer with mutex. - Make testcase "harder" to more easily trigger race conditions.
- Properly implement destructor (in inherited classes)! -> Destroy may not be called in base CMsgSubscriber class as this can lead to stack unwinding (most likely causes an exception in destructor, or leads to already deleted functions of derived class being called when they are already deleted) - Correct order of RemReceiveCallback and resetting internal pointer - protect function pointer with mutex. - Make testcase "harder" to more easily trigger race conditions.
- Properly implement destructor (in inherited classes)! -> Destroy may not be called in base CMsgSubscriber class as this can lead to stack unwinding (most likely causes an exception in destructor, or leads to already deleted functions of derived class being called when they are already deleted) - Correct order of RemReceiveCallback and resetting internal pointer - protect function pointer with mutex. - Make testcase "harder" to more easily trigger race conditions.
Cherry-pick to